<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('检查情况')" />
    <th:block th:include="include :: jasny-bootstrap-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-photo-add">
            <input name="dzbm" th:value="${dzbm}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">检查情况：</label>
                <div class="col-sm-8">
                    <input name="checkInfo" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">图片：</label>
                <div class="col-sm-8 fileinput fileinput-new" data-provides="fileinput" style="text-align: center; margin-bottom: 0;">
                    <div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 200px; height: 150px; margin-right: 10px;"></div>
                    <span class="btn btn-white btn-file">
                        <span class="fileinput-new">拍照</span>
                        <span class="fileinput-exists">更改</span>
                        <input name="photo" type="hidden" value="">
                        <input id="williamYe" accept="image/*" capture="camera" type="file">
                    </span>
                    <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: jasny-bootstrap-js"/>
    <script type="text/javascript">
        var prefix = ctx + "control/checkPhoto";

        $('#williamYe').on('change.bs.fileinput ', function (e) {
            // 处理自己的业务
            if(this.files[0]){
                const formData = new FormData();
                formData.append('file',this.files[0]);
                $.operate.fileUpload(formData, $('input[name="photo"]'));
            }else{
                $('input[name="photo"]').val("");
            }
        });


        $("#form-photo-add").validate({
            focusCleanup: true
        });


        function submitHandler() {
            if ($.validate.form()) {
                $.post($.common.setURL(prefix + "/add"), $('#form-photo-add').serialize(),function (res) {
                    if (res.success){
                        $.modal.close();
                        parent.$.modal.msgSuccess(res.message);
                    }
                });
            }
        }
    </script>
</body>
</html>
